home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / NDK / NDK_1.3 / Read-Me1.3 / Printer1.3 / Driver.Examples / src / epsonQ / transfer.c < prev   
Encoding:
C/C++ Source or Header  |  1988-08-01  |  2.8 KB  |  115 lines

  1. /*
  2.     Transfer routine for EpsonQ driver.
  3.     David Berezowski - October/87
  4. */
  5.  
  6. #include <exec/types.h>
  7. #include "../printer/printer.h"
  8. #include "../printer/prtbase.h"
  9. #include "../printer/prtgfx.h"
  10.  
  11. Transfer(PInfo, y, ptr, colors)
  12. struct PrtInfo *PInfo;
  13. UWORD y;    /* row # */
  14. UBYTE *ptr;    /* ptr to buffer */
  15. UWORD *colors; /* indexes to color buffers */
  16. {
  17.     extern struct PrinterData *PD;
  18.     extern struct PrinterExtendedData *PED;
  19.  
  20.     static UWORD bit_table[8] = {128, 64, 32, 16, 8, 4, 2, 1};
  21.     union colorEntry *ColorInt;
  22.     UBYTE *bptr, *yptr, *mptr, *cptr, Black, Yellow, Magenta, Cyan;
  23.     UBYTE *dmatrix, dvalue, threshold;
  24.     UWORD x, width, sx, *sxptr, color, bit, x3, ymod;
  25.  
  26.     /* pre-compute */
  27.     /* printer non-specific, MUST DO FOR EVERY PRINTER */
  28.     x = PInfo->pi_xpos;
  29.     ColorInt = PInfo->pi_ColorInt;
  30.     sxptr = PInfo->pi_ScaleX;
  31.     width = PInfo->pi_width;
  32.     /* printer specific */
  33.     x3 = x * 3;
  34.     ymod = y % PED->ped_NumRows;
  35.     bit = bit_table[ymod & 7];
  36.     ptr += ymod >> 3;
  37.     bptr = ptr + colors[0];
  38.     yptr = ptr + colors[1];
  39.     mptr = ptr + colors[2];
  40.     cptr = ptr + colors[3];
  41.  
  42.     /* pre-compute threshold; are we thresholding? */
  43.     if (threshold = PInfo->pi_threshold) { /* thresholding */
  44.         dvalue = threshold ^ 15;
  45.         bptr += x3;
  46.         do { /* for all source pixels */
  47.             /* pre-compute intensity values for each component */
  48.             Black = ColorInt->colorByte[PCMBLACK];
  49.             ColorInt++;
  50.  
  51.             sx = *sxptr++;
  52.  
  53.             do { /* use this pixel 'sx' times */
  54.                 if (Black > dvalue) {
  55.                     *bptr |= bit;
  56.                 }
  57.                 bptr += 3;
  58.             } while (--sx);
  59.         } while (--width);
  60.     }
  61.     else { /* not thresholding, pre-compute ptr to dither matrix */
  62.         dmatrix = PInfo->pi_dmatrix + ((y & 3) << 2);
  63.         if (PD->pd_Preferences.PrintShade == SHADE_GREYSCALE) { 
  64.             bptr += x3;
  65.             do { /* for all source pixels */
  66.                 /* compute intensity val for each component */
  67.                 Black = ColorInt->colorByte[PCMBLACK];
  68.                 ColorInt++;
  69.  
  70.                 sx = *sxptr++;
  71.  
  72.                 do { /* use this pixel 'sx' times */
  73.                     if (Black > dmatrix[x & 3]) {
  74.                         *bptr |= bit;
  75.                     }
  76.                     x++; /* done 1 more printer pixel */
  77.                     bptr += 3;
  78.                 } while (--sx);
  79.             } while (--width);
  80.         }
  81.         else { /* color */
  82.             do { /* for all source pixels */
  83.                 /* compute intensity val for each component */
  84.                 Black = ColorInt->colorByte[PCMBLACK];
  85.                 Yellow = ColorInt->colorByte[PCMYELLOW];
  86.                 Magenta = ColorInt->colorByte[PCMMAGENTA];
  87.                 Cyan = ColorInt->colorByte[PCMCYAN];
  88.                 ColorInt++;
  89.  
  90.                 sx = *sxptr++;
  91.  
  92.                 do { /* use this pixel 'sx' times */
  93.                     dvalue = dmatrix[x & 3];
  94.                     if (Black > dvalue) {
  95.                         *(bptr + x3) |= bit;
  96.                     }
  97.                     else  { /* black not rendered */
  98.                         if (Yellow > dvalue) {
  99.                             *(yptr + x3) |= bit;
  100.                         }
  101.                         if (Magenta > dvalue) {
  102.                             *(mptr + x3) |= bit;
  103.                         }
  104.                         if (Cyan > dvalue) {
  105.                             *(cptr + x3) |= bit;
  106.                         }
  107.                     }
  108.                     x++; /* done 1 more printer pixel */
  109.                     x3 += 3;
  110.                 } while (--sx);
  111.             } while (--width);
  112.         }
  113.     }
  114. }
  115.